import { createStore } from 'vuex'

export default createStore({
  state: {
    token: localStorage.getItem('token') || null,
    kind: localStorage.getItem('kind') || null
  },
  getters: {
    getToken: state => {
      return state.token
    },
    getKind: state => {
      return state.kind
    }
  },
  mutations: {
    setToken (state, token) {
      state.token = token
      localStorage.setItem('token', token)
    },
    removeToken (state) {
      state.token = null
      localStorage.removeItem('token')
    },
    setKind (state, kind) {
      state.kind = kind
    }
  },
  actions: {
    updateToken ({ commit }, token) {
      commit('setToken', token)
    },
    logout ({ commit }) {
      commit('removeToken')
    },
    updateKind ({ commit }, kind) {
      commit('setKind', kind)
    }
  },
  modules: {
  }
})
